package presentation;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.text.DecimalFormat;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import control.CControl;
import entity.ENumberRegister;
import entity.EPatternRegister;

public class PLabel extends JPanel implements Observer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel static_label;
	private JLabel value_label;
	private JLabel unit_label;
	private DecimalFormat df = new DecimalFormat("#.##");
	
	public PLabel(CControl cControl,String reg_name,String visble_name)
	{
		static_label = new JLabel(visble_name);
		static_label.setHorizontalAlignment(JLabel.LEFT);
		
		unit_label = new JLabel(cControl.getRegisterUnit(reg_name));
		unit_label.setHorizontalAlignment(JLabel.LEFT);
		
		value_label = new JLabel("-");
		value_label.setHorizontalAlignment(JLabel.CENTER);
		
		cControl.addRegisterObserver(reg_name, this);
		GridLayout b = new GridLayout(1,3);
		
		this.setLayout(b);
		
		this.add(static_label);
		this.add(value_label);
		this.add(unit_label);
		
		this.setBackground(Color.white);
		
		
	}
	@Override
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub
		if(arg1 instanceof Number)
		{
			value_label.setText("" + df.format(arg1));
		}
		else
		{
			value_label.setText(arg1.toString());
		}
	}

}

